import { http } from '@/utils/http'

export const createOrderAPI = (data: any) => {
  return http<any>({
    method: 'POST',
    url: '/shop/consume/mobile/order/order',
    data,
  })
}

export const toPayOrderAPI = (orderNos: any) => {
  return http<any>({
    method: 'GET',
    url: `/shop/consume/mobile/order/order/toPay/${orderNos}`,
  })
}

/**
 * 获取订单详情
 * @param id 订单id
 */
export const getMemberOrderByIdAPI = (id: string) => {
  return http<any>({
    method: 'GET',
    url: `/shop/consume/mobile/order/order/${id}`,
  })
}

/**
 * 模拟发货-内测版
 * @description 在DEV环境下使用，仅在订单状态为待发货时，可模拟发货，调用后订单状态修改为待收货，包含模拟物流。
 * @param id 订单id
 */
export const getMemberOrderConsignmentByIdAPI = (id: string) => {
  return http({
    method: 'GET',
    url: `/member/order/consignment/${id}`,
  })
}

/**
 * 确认收货
 * @description 仅在订单状态为待收货时，可确认收货。
 * @param orderNos 订单号
 */
export const putMemberOrderReceiptByIdAPI = (orderNos: string[]) => {
  return http<any>({
    method: 'PUT',
    url: `/shop/consume/mobile/order/order/confirmReceipt/${orderNos}`,
  })
}

export const postMemberOrderRepetitiveBuyingAPI = (orderId: string | number) => {
  return http<any>({
    method: 'POST',
    url: `/shop/consume/mobile/order/order/repetitiveBuying/${orderId}`,
  })
}

/**
 * 获取订单物流
 * @description 仅在订单状态为待收货，待评价，已完成时，可获取物流信息。
 * @param id 订单id
 */
export const getMemberOrderLogisticsByIdAPI = (id: string) => {
  return http<any>({
    method: 'GET',
    url: `/member/order/${id}/logistics`,
  })
}

/**
 * 删除订单
 * @description 仅在订单状态为待评价，已完成，已取消时，可删除订单。
 * @param id
 */
export const deleteMemberOrderAPI = (id: string | number) => {
  return http({
    method: 'DELETE',
    url: `/shop/consume/mobile/order/order/remove/${id}`,
  })
}

/**
 * 取消订单
 * @description 仅在订单状态为待付款时，可取消订单。
 * @param id 订单id
 * @param data cancelReason 取消理由
 */
export const getMemberOrderCancelByIdAPI = (id: string, data: { cancelReason: string }) => {
  return http<any>({
    method: 'PUT',
    url: `/member/order/${id}/cancel`,
    data,
  })
}

/**
 * 获取订单列表
 * @param data orderState 订单状态
 */
export const getMemberOrderAPI = (data: any) => {
  if (data.status == 999) {
    data.status = undefined
  }
  return http<any>({
    method: 'GET',
    url: `/shop/consume/mobile/order/order/list`,
    data,
  })
}
